package com.lhy.controller;


import com.lhy.pojo.Devices;
import com.lhy.pojo.Repair;
import com.lhy.service.DevicesService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("devices")
public class DevicesController {
    @Resource
    private DevicesService devicesService;

    //添加矿工信息到mongodb
    @PostMapping("add")
    public String addDevices(Devices devices){
        devicesService.addDevices(devices);
        return "设备添加成功";
    }

    //更新设备信息
    // 添加维修记录
    @PostMapping("update")
    public String updateDeviceAndRepair(Repair repair){
        devicesService.updateDeviceAndRepair(repair);
        return "维修信息添加成功";
    }

    //通过设备id查询
    @GetMapping("{deviceId}")
    public Devices selectDeviceById(@PathVariable String deviceId){
        return devicesService.selectDeviceById(deviceId);
    }

    //根据设备编号修改设备信息
    @PostMapping("updateInfo")
    public String updateDevicesInfo(Devices devices){
        devicesService.updateDevicesInfo(devices);
        return "修改成功";
    }

    //查询所有
    @GetMapping("list")
    public Map<String,Object> selectDevicesList(){
        return devicesService.selectDevicesList();
    }

    //查询所有使用中设备
    @GetMapping("listOn")
    public Map<String,Object> selectDevicesListOn(){
        return devicesService.selectDevicesListOn();
    }

    //查询所有未使用设备
    @GetMapping("listOff")
    public Map<String,Object> selectDevicesListOff(){
        return devicesService.selectDevicesListOff();
    }

    //查询所有维修中设备
    @GetMapping("listRepair")
    public Map<String,Object> selectDevicesListRepair(){
        return devicesService.selectDevicesListRepair();
    }


    //根据设备编号删除设备信息
    @PostMapping("delete")
    public String deleteDevicesById(String id){
        devicesService.deleteDevicesById(id);
        return "删除成功";
    }
}
